<template>
	<div class="app-container">
		<el-tabs type="card" @tab-click="handleClick" v-model="activeName">
			<el-tab-pane label="任务地图" name="first">
				<!--<p>任务地图</p>-->
				<SceneexamineMap v-if="completeRefreshSceneexamine" :allListData="allListData"
					:isSaveMapPolygon="isSaveMapPolygon" :surveyList="surveyList" :districtTreeList="districtTreeList"
					:taskRegionResultNameCodeList="taskRegionResultNameCodeList" :importShpTxtWkt="importShpTxtWkt"
					@xzqhSelect="xzqhSelect" @mapNewTask="mapNewTask" @mapUpdTask="mapUpdTask" @mapDelTask="mapDelTask"
					@newMapSurvey="newMapSurvey" @mapLoading="mapLoading" @getSurveyList="getSurveyList" @mapShowTask="mapShowTask"
					@mapGetSurvey="mapGetSurvey" @queryTaskRegionNameCodeListByGeomText="queryTaskRegionNameCodeListByGeomText"
					@importShpTxt="showHideUploadDiv(true)"></SceneexamineMap>
				<!--上传面板-->
				<div v-if="showHideUploadDivBool" class="new-uploadDiv">
					<div class="new-uploadDiv-inner">
						<span style="position: relative;top: -2px;font-size: 14px;">导入文件类型：</span>
						<el-radio-group v-model="uploadType" @change="changeUploadType">
							<el-radio label="0">shp</el-radio>
							<el-radio label="1">txt</el-radio>
						</el-radio-group>
						<div class="new-fileBtn">
							<template v-if="uploadType == '0'">
								<input type="file" @change="uploadFileChange" style="width: 70px;" id="sceneexamine-button-selectfile-shp"
									multiple="multiple" accept=".shp,.dbf,.prj,.sbn,.sbx,.shp.xml,.shx,.cpg" />
							</template>
							<template v-if="uploadType == '1'">
								<input type="file" @change="uploadFileChange" style="width: 70px;" id="sceneexamine-button-selectfile-txt"
									multiple="multiple" accept=".txt" />
							</template>
						</div>
						<div class="new-fieldInfoBtn" v-if="uploadType == '1'">
							<a @click="importTemplate('导入工作区域经纬度模板.txt')">
								<h5>下载模板</h5>
							</a>
						</div>
						<div class="new-filesTextArea">
							<template v-if="uploadType == '0'">
								<el-input type="textarea" :rows="5" placeholder="导入多个文件时，文件名须相同；至少需要导入1个.shp文件和1个.prj文件"
									v-model="textarea" readonly></el-input>
							</template>
							<template v-else>
								<el-input type="textarea" :rows="5"
									placeholder="导入1个.txt文件，内容包括可组成1个面的多个点的经纬度数据，具体格式请参照下载模板内容（即经度和纬度用制表符间隔）" v-model="textarea"
									readonly></el-input>
							</template>
						</div>
						<div class="new-uploadBtnDiv">
							<el-button @click="uploadFileClick" type="primary">上传</el-button>
						</div>
						<div class="new-closeBtnDiv">
							<el-button plain @click="showHideUploadDiv(false)">关闭</el-button>
						</div>
					</div>
				</div>
			</el-tab-pane>
			<el-tab-pane label="任务列表" name="second">
				<!-- header -->
				<!-- 头部任务状态区域 -->
				<el-form :model="queryParams" ref="queryRef" :inline="true" label-width="100px">
					<el-form-item label="任务编号" prop="taskNum">
						<el-input placeholder="请输入任务编号" v-model="queryParams.taskNum" clearable @keyup.enter="handleQuery" />
					</el-form-item>

					<el-form-item label="任务名称" prop="taskName">
						<el-input placeholder="请输入任务名称" clearable v-model="queryParams.taskName" />
					</el-form-item>

					<el-form-item label="任务状态" prop="status">
						<el-select v-model="queryParams.taskStatus" clearable placeholder="请选择状态">
							<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
						</el-select>
					</el-form-item>
					<el-form-item label="省" prop="province">
						<el-select v-model="queryParams.province" placeholder="请选择省" @change="chooseProvince" clearable
							value-key="id">
							<el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="市" prop="city">
						<el-select v-model="queryParams.city" placeholder="请选择市" @change="chooseCity" clearable value-key="id">
							<el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="区/县" prop="county">
						<el-select v-model="queryParams.county" placeholder="请选择县" @change="chooseCounty" clearable value-key="id">
							<el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item">
							</el-option>
						</el-select>
					</el-form-item>
					<!-- 查询 重置按钮 -->
					<el-form-item>
						<el-button type="primary" @click="handleQuery">查询</el-button>
						<el-button plain @click="resetQuery">重置</el-button>
					</el-form-item>
				</el-form>

				<el-row :gutter="10" class="mb8">
					<el-col :span="1.5">
						<el-button plain icon="Delete" :disabled="multiple" @click="handleDelete">删除</el-button>
						<!--<el-button type="primary" plain :disabled="multiple" @click="handleEnd">结束</el-button>-->
					</el-col>
				</el-row>
				<!-- container表格区域 -->
				<el-table :data="listData" v-loading="loading" row-key="id" ref="tableRef" stripe
					@selection-change="handleSelectionChange">
					<el-table-column type="selection" width="55" align="center" :reserve-selection="true" />
					<el-table-column label="任务编号" align="center" prop="taskNum" />
					<el-table-column label="任务名称" align="center" prop="taskName">
						<template #default="scope">
							<span @click="handleDetail(scope.row.id)" style="color: var(--el-color-primary); cursor: pointer;">{{
								scope.row.taskName
							}}</span>
						</template>
					</el-table-column>
					<el-table-column label="任务管理员" align="center" prop="taskManager" width="140px" />
					<el-table-column label="任务状态" align="center" prop="taskStatus" width="140px">
						<template #default="scope">
							<div v-if="scope.row.taskStatus == 0">未分配</div>
							<div v-else-if="scope.row.taskStatus == 1">进行中</div>
							<div v-else>已结束</div>
						</template>
					</el-table-column>
					<el-table-column label="承担小组" align="center" prop="groupName" />
					<el-table-column label="组长" align="center" prop="groupLeader" width="140px" />
					<el-table-column label="任务地区" align="center" prop="taskDistrict" show-overflow-tooltip />
					<el-table-column label="所属父任务" align="center" prop="parentTask">
						<template #default="scope">
							<div v-if="scope.row.parentId == 0"></div>
							<div v-else>{{ scope.row.parentTask }}</div>
						</template>
					</el-table-column>
					<el-table-column label="操作" align="center" width="350px" class-name="small-padding fixed-width">
						<template #default="scope">
							<template v-if="scope.row.taskStatus != '2'">
								<template v-if="scope.row.parentId == 0">
									<el-button type="text" @click="updateParentHandle(scope.row)">修改</el-button>
								</template>
								<template v-else>
									<el-button type="text" @click="updateSubHandle(scope.row)">修改</el-button>
								</template>
								<el-button type="text" @click="addSub(scope.row)"
									v-if="!scope.row.groupId && scope.row.parentId == 0 && getProvinceCodeByAllName(scope.row.taskDistrict).length > 1 && scope.row.children.length < getProvinceCodeByAllName(scope.row.taskDistrict).length">新建子任务</el-button>
								<template v-if="scope.row.children.length == 0 && !scope.row.groupId">
									<el-button type="text" @click="fenPei(scope.row)">分配</el-button>
								</template>
								<el-button plain v-if="scope.row.children.length == 0" type="text"
									@click="probeOpen(scope.row)">新建调研点</el-button>
							</template>
							<el-button type="text" @click="openTrack(scope.row)" v-if="scope.row.flag">查看行动轨迹</el-button>
							<el-button plain v-if="scope.row.taskStatus == '1'" type="text" @click="handleEnd(scope.row)">结束</el-button>
						</template>
					</el-table-column>
				</el-table>
				<pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
					@pagination="getList" />
			</el-tab-pane>
		</el-tabs>
		<!-- 查看弹出框 -->
		<el-dialog v-model="openDetail" title="查看任务" width="900px" append-to-body>
			<p class="dialogTitle">查看任务</p>
			<detailAssess :detilList="detilList" />
		</el-dialog>
		<!--新建/修改任务的弹出框 -->
		<el-dialog v-model="openAdd" :title="title" width="800px" append-to-body>
			<p class="dialogTitle">{{ title }}</p>
			<table class="addTask">
				<div v-if="title != '修改任务'">
					<el-form :model="queryParamsAdd" :rules="rules" ref="rulesFormAdd" :inline="true" label-width="140px">
						<el-form-item label="任务年份：" prop="taskYear" v-if="title == '新建任务'">
							<el-select placeholder="请选择年份" v-model="queryParamsAdd.taskYear" @change="changeYear" clearable>
								<el-option v-for="item in optionsYear" :key="item.id" :label="item.label"
									:value="item.value" /></el-select>
						</el-form-item>
						<el-form-item>
							<span class="label">任务编号：</span><span>{{ queryParamsAdd.taskNum }}</span>
						</el-form-item>
						<el-form-item label="任务名称：" prop="taskName" style="width:90%">
							<el-input placeholder="请输入任务名称" clearable v-model="queryParamsAdd.taskName" />
						</el-form-item>
					</el-form>
				</div>
				<tr v-if="title == '修改任务'">
					<td><span class="label">任务年份：</span><span>{{ queryParamsAdd.taskYear }}</span></td>
					<td><span class="label">任务编号：</span><span>{{ queryParamsAdd.taskNum }}</span></td>
				</tr>
				<tr v-if="title == '修改任务'">
					<td colspan="2">
						<el-form :model="queryParamsAdd" :rules="rules" ref="rulesFormAdd" :inline="true" label-width="140px">
							<el-form-item label="任务名称：" prop="taskName" style="width:90%">
								<el-input placeholder="请输入任务名称" clearable v-model="queryParamsAdd.taskName" />
							</el-form-item>
						</el-form>
					</td>
				</tr>
				<tr>
					<td colspan="2"><span class="label">面积（平方公里）：</span><span>{{ queryParamsAdd.taskArea }}</span></td>
				</tr>
				<tr>
					<td colspan="2"><span class="label">任务区域：</span><span class="init-taskDivSpan">{{
						queryParamsAdd.taskRegion.substr(0, 358) }}...</span></td>
				</tr>
				<tr>
					<td colspan="2"><span class="label">任务地区：</span>
						<span class="init-taskDivSpan" v-if="title == '新建任务'">
							{{ taskDistrictName }}
						</span>
						<span class="init-taskDivSpan" v-else>
							{{ queryParamsAdd.taskDistrict }}
						</span>
					</td>
				</tr>
				<tr v-if="queryParamsAdd.groupName != ''">
					<td colspan="2"><span class="label">承担小组：</span><span>{{ queryParamsAdd.groupName }}</span>
						<el-button plain style="margin-left:20px" @click="fenPeiAdd">修改分配</el-button>
					</td>
				</tr>
			</table>
			<div v-if="title == '新建任务' && subTaskData.length > 0">
				<h3>子任务列表</h3>
				<div class="wrapBox" style="width: 100%">
					<el-table v-loading="loading1" :data="subTaskData" stripe>
						<el-table-column prop="taskNum" align="center" label="子任务编号" show-overflow-tooltip />
						<el-table-column prop="taskName" align="center" label="子任务名称" show-overflow-tooltip />
						<el-table-column prop="taskDistrict" align="center" label="所在省" show-overflow-tooltip />
						<el-table-column prop="groupName" align="center" label="承担小组" show-overflow-tooltip />
						<el-table-column prop="operation" label="操作" align="center">
							<template #default="scope">
								<template v-if="!scope.row.groupId">
									<el-button type="text" @click="fenPei(scope.row)">分配</el-button>
								</template>
								<el-button type="text" @click="updateSubHandle(scope.row)">修改</el-button>
								<el-button type="text" @click="delSubTask(scope.row)">删除</el-button>
							</template>
						</el-table-column>
					</el-table>
					<!-- <pagination
            v-show="total1 > 0"
            :total="total1"
            v-model:page="subDataPage.page"
            v-model:limit="subDataPage.rows"
            @pagination="getSubList"
          /> -->
				</div>
			</div>
			<template #footer>
				<span class="dialog-footer" style="text-align: center!important">
					<template v-if="title == '新建任务' && queryParamsAdd.groupName == ''">
						<el-button type="primary" @click="addSub2(queryParamsAdd)"
							v-if="getProvinceCodeByAllName(taskDistrictName.replace(/,/g, '、')).length > 1 && subTaskData.length != getProvinceCodeByAllName(taskDistrictName.replace(/,/g, '、')).length">新建子任务</el-button>
					</template>
					<template v-if="subTaskData.length == 0 &&
						title == '新建任务' &&
						queryParamsAdd.groupName == ''
						">
						<el-button type="primary" @click="fenPeiAdd()">分配小组</el-button>
					</template>
					<template v-if="subTaskData.length == 0">
						<el-button type="primary" @click="okAdd">保 存</el-button>
					</template>
					<template v-else>
						<el-button type="primary" @click="closeAdd">保 存</el-button>
					</template>
					<template v-if="subTaskData.length == 0">
						<el-button plain @click="cancelAdd">取 消</el-button>
					</template>
				</span>
			</template>
		</el-dialog>
		<!--新建/修改子任务的弹出框 -->
		<el-dialog v-model="openAddSub" v-if="openAddSub" :title="titleSub" width="900px" append-to-body>
			<p class="dialogTitle">{{ titleSub }}</p>
			<table class="addSubTask">
				<tr>
					<td><span class="label">子任务编号：</span><span>{{ queryParamsSubAdd.taskNum }}</span></td>
					<td v-if="titleSub == '修改子任务'"><span class="label">所属父任务：</span><span>{{ queryParamsSubAdd.parentTask }}</span>
					</td>
					<td v-if="titleSub == '新建子任务'"><span class="label">所属父任务：</span><span>{{ parentTaskCode }}</span></td>
				</tr>
				<tr v-if="titleSub == '新建子任务'">
					<td colspan="2">
						<el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" label-width="140px">
							<el-form-item label="子任务名称：" prop="taskName">
								<el-input placeholder="请输入子任务名称" clearable v-model="queryParamsSubAdd.taskName" />
							</el-form-item>
						</el-form>
					</td>
				</tr>
				<tr v-if="titleSub == '新建子任务'">
					<td>
						<el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" label-width="140px">
							<el-form-item label="所在省：" prop="subdistrictList">
								<el-select placeholder="请选择省" v-model="queryParamsSubAdd.subdistrictList" clearable>
									<el-option
										v-for="item in districtListName.filter(item => !subTaskData.some(cur => cur.taskDistrict.includes(item.value)))"
										:key="item.id" :label="item.label" :value="item.value" />
								</el-select>
							</el-form-item>
						</el-form>
					</td>
					<td>
						<el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" label-width="140px">
							<el-form-item v-if="queryParamsSubAdd.groupName != ''">
								<span class="label">承担小组:</span><span>{{ queryParamsSubAdd.groupName }}</span>
							</el-form-item>
						</el-form>
					</td>
				</tr>
				<tr v-if="titleSub == '修改子任务'">
					<td colspan="2">
						<el-form :model="queryParamsSubAdd" :rules="rules2" ref="rulesFormSubAdd" :inline="true" label-width="140px">
							<el-form-item label="子任务名称：" prop="taskName" style="width:90%">
								<el-input placeholder="请输入子任务名称" clearable v-model="queryParamsSubAdd.taskName" />
							</el-form-item>
						</el-form>
					</td>
				</tr>
				<tr v-if="titleSub == '修改子任务'">
					<td colspan="2"><span class="label">任务区域：</span><span>{{ queryParamsSubAdd.taskDistrict }}</span></td>
					<!--<td><span class="label">所属父任务：</span><span>{{queryParamsSubAdd.parentTask}}</span></td>-->
				</tr>
				<tr v-if="queryParamsSubAdd.groupName != '' && titleSub == '修改子任务'">
					<td><span class="label">承担小组：</span><span>{{ queryParamsSubAdd.groupName }}</span>
						<el-button plain style="margin-left:20px" @click="fenPeiAdd()">修改分配</el-button>
					</td>
				</tr>
			</table>
			<div v-if="titleSub == '新建子任务'">
				<h3><span></span> 分配小组</h3>
				<fpGrop @queryGroup="queryGroup" ref="fpRef" />
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button type="primary" @click="okSubAdd">保 存</el-button>
					<template v-if="titleSub == '新建子任务'">
						<el-button type="primary" @click="okSubAddNext">保存并创建下一个</el-button>
					</template>
					<el-button plain @click="cancelAddSub">取 消</el-button>
				</span>
			</template>
		</el-dialog>
		<!-- 分配的弹出框 -->
		<el-dialog v-model="openFp" v-if="openFp" title="分配小组" width="900px" append-to-body>
			<p class="dialogTitle">分配小组</p>
			<fpGrop @queryGroup="queryGroup" ref="fpRef" />
			<!-- <template #footer>
        <div class="dialog-footer">
          <el-button
              type="primary"
              @click="okFp()"
              :disabled="queryGroupObj == undefined"
          >确 定</el-button
          >
          <el-button @click="cancelP">取 消</el-button>
        </div>
      </template> -->
		</el-dialog>
		<!-- 行政区域选择 -->
		<div class="areaDialog" v-show="openArea">
			<div class="close">
				<el-icon>
					<Close @click="closeSelect" />
				</el-icon>
			</div>
			<el-form :model="form" :rules="rules" ref="rulesForm" label-width="100px">
				<el-form-item label="选择地区" prop="taskDistrict" style="width:280px">
					<el-cascader v-model="form.taskDistrict" placeholder="请选择地区" :props="props" clearable separator=","
						collapse-tags collapse-tags-tooltip @change="getCheckedArea" ref="checkedAreaRef" :options="optionsSelect">
					</el-cascader>
				</el-form-item>
			</el-form>
			<el-button @click="add()" type="primary" style="margin:20px 0">新建任务</el-button>
		</div>
		<!-- 选择子任务的弹出框 -->
		<el-dialog v-model="openSubTask" title="选择子任务" width="600px" append-to-body>
			<el-table v-loading="loading1" :data="subTaskData" stripe>
				<el-table-column prop="taskNum" align="center" label="子任务编号" show-overflow-tooltip />
				<el-table-column prop="taskName" align="center" label="子任务名称" show-overflow-tooltip />
				<el-table-column prop="groupName" align="center" label="承担小组" show-overflow-tooltip />
				<el-table-column prop="operation" label="操作" align="center">
					<template #default="scope">
						<el-button type="text" @click="probeOpen(scope.row)">选择</el-button>
					</template>
				</el-table-column>
			</el-table>
			<template #footer>
				<div class="dialog-footer">
					<el-button plain @click="openSubTask = false">取 消</el-button>
				</div>
			</template>
		</el-dialog>

		<el-dialog v-model="openEndTask" title="结束任务" width="900px" :close-on-click-modal="false" append-to-body
			:show-close="false">
			<div v-for="(item, index) in endTaskList" :key="item.rk.id">
				<div v-if="index == initIndex">
					<p class="mainTitle">{{ item.rk.province }}{{ item.rk.city }}{{ item.rk.area
					}}有“已入库”的区县致死性差异性指标数据，请选择是否更新该区县的指标值？</p>
					<p class="subTitle">已入库指标</p>
					<table class="tableDialog">
						<tr class="tableHead">
							<td>建筑物</td>
							<td>人口</td>
							<td>地形地貌</td>
							<td>道路交通</td>
							<td>气候</td>
							<td v-for="subitem in item.rk.customIndicatorList">{{ subitem.customIndicatorName }}</td>
						</tr>
						<tr>
							<td>
								<span>{{ item.rk.building }}</span>

							</td>
							<td>
								<span>{{ item.rk.peopleNum }}</span>
							</td>
							<td>
								<span>{{ item.rk.terrain }}</span>
							</td>
							<td>
								<span>{{ item.rk.traffic }}</span>
							</td>
							<td>
								<span>{{ item.rk.climate }}</span>
							</td>
							<td v-for="subitem in item.rk.customIndicatorList">
								<span>{{ subitem.customIndicatorValue }}</span>
							</td>
						</tr>
					</table>
					<p class="subTitle">当前任务指标</p>
					<table class="tableDialog">
						<tr class="tableHead">
							<td>建筑物</td>
							<td>人口</td>
							<td>地形地貌</td>
							<td>道路交通</td>
							<td>气候</td>
							<td v-for="subitem in item.cn.customIndicatorList">{{ subitem.customIndicatorName }}</td>
						</tr>
						<tr>
							<td>
								<span>{{ item.cn.building }}</span>

							</td>
							<td>
								<span>{{ item.cn.peopleNum }}</span>
							</td>
							<td>
								<span>{{ item.cn.terrain }}</span>
							</td>
							<td>
								<span>{{ item.cn.traffic }}</span>
							</td>
							<td>
								<span>{{ item.cn.climate }}</span>
							</td>
							<td v-for="subitem in item.cn.customIndicatorList">
								<span>{{ subitem.customIndicatorValue }}</span>
							</td>
						</tr>
					</table>

					<!--<template #footer>-->
					<div class="dialog-footer">
						<el-button type="primary" @click="update(item.rk.id, item.cn.id, index)" :disabled="isUpdate">更新</el-button>
						<el-button plain @click="unUpdate(index)">不更新</el-button>
					</div>
					<!--</template>-->
				</div>
			</div>
		</el-dialog>
	</div>
</template>
<script setup name="sceneexamine">
import { mapAllListSurvey } from "@/api/basedatamanage/survey.js";
//地图空间分析
import { getSubTaskRegionIntersection } from "@/map/taskmanage/sceneexamine/mapUtil.js";
//地图
import SceneexamineMap from '@/map/taskmanage/sceneexamine/map.vue';
import fpGrop from "@/components/FpGroup/index.vue";
import detailAssess from "./detailAssess.vue"
import { getProvince, getChildArea } from "@/api/system/division";
import { getProvinces, getYear, getDistrict } from "@/utils/group.js";
import { queryProvinceCityCountyNameCodeListByGeomText } from "@/api/taskmanage/taskRegionQuery";
import {
	getTask,
	delTask,
	updateTask,
	addSubTask,
	addTask,
	detailTask,
	groupFp,
	getTaskBian,
	getSubTaskBian,
	getSubTask,
	completeTask,
	checkIsAdopted,
	checkPutLethalityDifference,
	updateIsAdoptByTaskNum,
	updateIsAdopt,
	getAreaTree,
	getDistrictBoundary,
	getAllTaskList
} from "@/api/taskmanage/sceneExame";
import { uploadShpFile, uploadTxtFile } from "@/api/taskmanage/taskRegionQuery";
import { ElMessageBox } from "element-plus";
const {
	proxy
} = getCurrentInstance();
const taskDistrictName = ref("");
const checkedAreaRef = ref();
const props = {
	multiple: true
};
const initIndex = ref(0);
const ids = ref([]);
const endTaskList = ref([]);
const single = ref(true);
const multiple = ref(true);
const openEndTask = ref(false);
const options = [
	{ value: "0", label: "未分配" },
	{ value: "1", label: "进行中" },
	{ value: "2", label: "已结束" }
];
const newYear = getYear();
const optionsYear = [{
	value: String(newYear),
	label: String(newYear),
	id: 1,
},
{
	value: String(newYear + 1),
	label: String(newYear + 1),
	id: 2,
},
{
	value: String(newYear + 2),
	label: String(newYear + 2),
	id: 3,
},
];
const loading = ref(true);
const loading1 = ref(true);
const provinceData = ref([]); //省
const cityData = ref([]); //市
const areaData = ref([]); //区、县
const openFp = ref(false);
const fpId = ref({
	id: undefined,
	parentId: undefined,
	taskName: undefined,
	createUser: undefined,
});
const openAdd = ref(false);
const openAddSub = ref(false);
const openArea = ref(false);
const openSubTask = ref(false);
const title = ref("");
const titleSub = ref("");
const activeName = ref("first");
const queryGroupObj = ref(undefined);
const openDetail = ref(false);
const total = ref(0);
const num = ref(2);
const parentTaskCode = ref();
const parentTaskYear = ref();
const parentTaskId = ref();
const numAdd = ref(2);
const districtListName = ref("");
const delFlag = ref(false);
const endFlag = ref(false);
const taskId = ref("");
const rules = reactive({
	taskDistrict: [{
		required: true,
		message: "请选择地区",
		trigger: "change"
	}],
	taskYear: [{
		required: true,
		message: "请选择年份",
		trigger: "blur"
	}],
	taskName: [{
		required: true,
		message: "请输入任务名称",
		trigger: "blur"
	}],
});
const rules2 = reactive({
	taskName: [{
		required: true,
		message: "请输入任务名称",
		trigger: "blur"
	}],
	subdistrictList: [{
		required: true,
		message: "请输入选择省份",
		trigger: "blur"
	}],
})
let detilList = reactive({
	preAssessTaskEntity: {
		taskYear: undefined,
		taskNum: undefined,
		taskName: undefined,
		taskArea: undefined,
		taskRegion: undefined,
		districtList: undefined,
		groupName: undefined,
		groupLeader: undefined,
		taskDistrict: undefined,
	},
	expertlist: undefined,
	memberlist: "",
});
const data = reactive({
	form: {
		taskDistrict: "",
	},
	selectProvince: [],
	listData: [],
	queryParams: {
		page: 1,
		rows: 10,
		taskNum: "",
		taskName: "",
		taskStatus: "",
		province: "",
		city: "",
		county: "",
	},
	queryParamsAdd: {
		taskYear: "",
		taskNum: "",
		taskName: "",
		taskArea: "",
		taskRegion: "",
		parentdistrictList: [],
		taskDistrict: '',
		groupName: "",
		groupLeader: "",
		groupId: "",
		groupLeaderId: "",
		regionCodes: "" //地图行政区划code,code字符串
	},
	queryParamsSubAdd: {
		taskYear: "",
		taskNum: "",
		taskName: "",
		taskArea: "",
		taskRegion: "",
		subdistrictList: "",
		taskDistrict: '',
		groupName: "",
		groupLeader: "",
		groupLeaderId: "",
		groupId: "",
		regionCodes: "" //地图行政区划code,code字符串
	},
	subTaskData: [],
	subDataPage: {
		page: 1,
		rows: 10,
	},
	optionsSelect: [],
	selectArea: []
});

let {
	form,
	queryParams,
	listData,
	queryParamsAdd,
	queryParamsSubAdd,
	selectArea,
	subTaskData,
	optionsSelect
} = toRefs(data);
const router = useRouter();
//地图传参--start
const completeRefreshSceneexamine = ref(false); //防止刷新后地图不显示
const allListData = ref([]);
const isSaveMapPolygon = ref(false); //判断是否完成保存任务区域
const xzqhSelect = () => { //行政区划选择区域
	areaSelect();
}
//导入工作区域shp/txt
const showHideUploadDivBool = ref(false);//是否显示上传面板
const uploadType = ref("0");//上传类型0shp 1txt
const textarea = ref("");//上传文件只读显示文本框
const minList = ref([]);//要上传的文件的后缀名数组
const nameList = ref([]);//要上传的文件的文件名数组
const importShpTxtWkt = ref("");//导入任务区域空间数据wkt
const showHideUploadDiv = (bool) => {
	importShpTxtWkt.value = "";
	textarea.value = "";
	showHideUploadDivBool.value = bool;
}
const changeUploadType = () => {//切换上传类型
	textarea.value = "";
}
const uploadFileChange = () => {//选择文件shp
	let uploadinputFiles = [];
	if (uploadType.value == "1") {//txt文件
		uploadinputFiles = document.getElementById("sceneexamine-button-selectfile-txt").files;
	} else {//shp文件
		uploadinputFiles = document.getElementById("sceneexamine-button-selectfile-shp").files;
	}
	minList.value = [];
	nameList.value = [];
	let text = "";
	for (let i = 0; i < uploadinputFiles.length; i++) {
		text += uploadinputFiles[i].name + "\n";
		// 获取这个文件的后缀名
		minList.value.push(uploadinputFiles[i].name.slice(uploadinputFiles[i].name.length - 3, uploadinputFiles[i].name.length));
		nameList.value.push(uploadinputFiles[i].name.split(".")[0]);
	}
	textarea.value = text;
}
const uploadFileClick = () => {//上传
	let uploadinput = null;
	if (textarea.value == "") {
		proxy.$modal.msgWarning("上传前请先选择文件!");
		return;
	}
	if (uploadType.value == "1") {//txt文件
		if (minList.value.length != 1) {
			proxy.$modal.msgWarning('上传数量限制:.txt文件1个');
			return;
		}
		uploadinput = document.getElementById("sceneexamine-button-selectfile-txt");
	} else {//shp文件
		if (!judgeIsOnce(minList.value)) {
			proxy.$modal.msgWarning('上传数量限制:.prj、.shp文件各1个');
			return;
		} else if (!judgeName(nameList.value)) {
			proxy.$modal.msgWarning("文件名请保持一致！");
			return;
		}
		uploadinput = document.getElementById("sceneexamine-button-selectfile-shp");
	}
	if (uploadinput != null && uploadinput.files.length == 0) {
		proxy.$modal.msgWarning("上传前请先选择文件!");
		return;
	}

	let formData = new FormData();
	for (let i = 0; i < uploadinput.files.length; i++) {
		formData.append('files', uploadinput.files[i]);
	}
	formData.append('uploadType', uploadType.value);
	mapLoading("正在上传...");
	if (uploadType.value == "1") {//txt文件
		uploadTxtFile(formData).then((response) => {
			nextTick(() => {
				let msg = response.data;
				mapLoading(null);
				let messageType = "error";
				if (msg.indexOf("导入成功.") != -1) {
					messageType = "success";
					importShpTxtWkt.value = msg.split("导入成功.")[1];
					msg = "导入成功";
				}
				ElMessageBox.alert(msg, '系统信息', {
					confirmButtonText: '确认',
					type: messageType,
					dangerouslyUseHTMLString: true,
				});
			});
		}).catch(err => {
			mapLoading(null);
		});
	} else {//shp文件
		uploadShpFile(formData).then((response) => {
			nextTick(() => {
				let msg = response.data;
				mapLoading(null);
				let messageType = "error";
				if (msg.indexOf("导入成功.") != -1) {
					messageType = "success";
					importShpTxtWkt.value = msg.split("导入成功.")[1];
					msg = "导入成功";
				}
				ElMessageBox.alert(msg, '系统信息', {
					confirmButtonText: '确认',
					type: messageType,
					dangerouslyUseHTMLString: true,
				});
			});
		}).catch(err => {
			mapLoading(null);
		});
	}
}
function importTemplate(name) {// 模板下载
	proxy.download("/taskRegionQuery/downloadTxt", {
		fileName: name
	}, name);
}
//校验shp文件类型
function judgeIsOnce(list) {
	// ["prj","shp"];
	let prj = 0, shp = 0;
	for (let i = 0; i < list.length; i++) {
		let item = list[i];
		if (item == 'prj') prj++;
		if (item == 'shp') shp++;
	}
	if (prj == 1 && shp == 1) return true;
	else return false;
}
//校验shp文件名称
function judgeName(list) {
	let name = list[0];
	let result = list.filter(function (item) {
		return item == name;
	})
	if (result.length == list.length) return true;
	else return false;
}

const mapNewTask = (temp) => { //新建任务
	isSaveMapPolygon.value = false; //判断是否完成保存任务区域
	getTaskNum();
	subTaskData.value = [];
	title.value = "新建任务";
	num.value = 0;
	openAdd.value = true;
	resetAdd();
	queryParamsAdd.value.taskArea = temp.taskArea;
	queryParamsAdd.value.taskRegion = temp.taskRegion;
	queryParamsAdd.value.parentdistrictList = temp.parentdistrictList;
	queryParamsAdd.value.regionCodes = ""; //地图行政区划code,code字符串
	taskDistrictName.value = temp.parentdistrictList.join(',');
	districtListName.value = getMapProvinces(taskDistrictName.value);
}
const mapUpdTask = (row) => { //修改任务
	updateParentHandle(row);
}
const mapDelTask = (row) => { //删除任务
	delSubTask(row);
}
const newMapSurvey = (row) => { //新建调研点
	loading1.value = false;
	let parentId = row.id;
	//先判断是否有子任务
	getSubTask({
		parentTaskId: parentId
	}).then((response) => {
		nextTick(() => {
			if (response.data.length > 0) { //有子任务
				subTaskData.value = response.data;
				openSubTask.value = true;
			} else { //没有子任务
				probeOpen(row);
			}
		});
	});
}
const mapLoading = (msg) => { //地图查询loading
	if (msg != null) {
		proxy.$modal.loading(msg);
	} else {
		proxy.$modal.closeLoading();
	}
}
const mapShowTask = (id) => { //查看任务
	handleDetail(id);
}
const detailSurveyId = ref(""); //地图选择调研点ID
const mapGetSurvey = (id) => { //查看调研点详情
	detailSurveyId.value = id;
}
//处理地图圈选省份
function getMapProvinces(taskDistrict) {
	const str = taskDistrict.replace(/-/g, ",")
	const arr = [...new Set(str.split(","))]
	let newArr = []
	arr.forEach(item => {
		if (item.indexOf('省') != -1) {
			newArr.push(item)
		} else if (item == '北京市' || item == '天津市' || item == '上海市' || item == '重庆市' || item == '内蒙古自治区' || item == '内蒙古自治区' || item == '广西壮族自治区' || item == '西藏自治区' || item == '宁夏回族自治区' || item == '新疆维吾尔自治区' || item == '香港特别行政区' || item == '澳门特别行政区') {
			newArr.push(item)
		}
	})
	let brr = []
	brr = newArr.map(
		(item, index) => {
			return Object.assign({}, {
				value: item,
				label: item,
				id: index + 1
			});
		}
	);
	return brr
}
//获取行政区划总面积
function getAllSelectArea(array) {
	let areaCount = 0;
	console.log(array.length);
	if (array != null && array.length > 0) {
		for (let i = 0; i < array.length; i++) {
			let name = array[i];
			let arr = name.split('-');
			console.log(name + "," + arr.length);
			if (arr.length == 1) { //省
				let province = arr[0];
				let areaTemp = getAreaByAllName("1", province, null, null); //根据行政区划全称获取省市区面积信息
				console.log("areaTemp" + areaTemp);
				areaCount += areaTemp;
				console.log("areaCount" + areaCount);
			} else if (arr.length == 2) { //市或直辖市的区县
				let province = arr[0];
				let city = arr[1];
				let areaTemp = getAreaByAllName("2", province, city, null); //根据行政区划全称获取省市区面积信息
				console.log("areaTemp" + areaTemp);
				areaCount += areaTemp;
				console.log("areaCount" + areaCount);
			} else if (arr.length == 3) { //区县
				let province = arr[0];
				let city = arr[1];
				let area = arr[2];
				let areaTemp = getAreaByAllName("3", province, city, area); //根据行政区划全称获取省市区面积信息
				console.log("areaTemp" + areaTemp);
				areaCount += areaTemp;
				console.log("areaCount" + areaCount);
			}
		}
	}
	if (areaCount > 0) {
		areaCount = areaCount.toFixed(3); //四舍五入保留3位小数
	}

	return areaCount;
}

function getAreaByAllName(type, province, city, area) { //根据行政区划全称获取省市区面积信息
	//type:0省 | 1市 | 2区县
	let areaCount = 0;
	let districtTreeDataList = districtTreeList.value;
	if (districtTreeDataList != null && districtTreeDataList != "") {
		//获取行政区划树列表
		let treeList = districtTreeDataList;
		if (treeList != null && treeList.length > 0) {
			for (let i = 0; i < treeList.length; i++) {
				let provinceData = treeList[i]; //省节点
				if (provinceData != null) {
					let provinceName = provinceData.name; //省
					if (type == "1" && province == provinceName) {
						let cityList = provinceData.children; //市列表
						if (cityList != null) {
							for (let j = 0; j < cityList.length; j++) {
								let cityData = cityList[j];
								if (cityData != null) {
									let areaList = cityData.children; //区县列表
									if (areaList != null && areaList.length > 0) {
										for (let j = 0; j < areaList.length; j++) {
											let areaData = areaList[j];
											if (areaData != null) {
												areaCount += areaData.area / 1000000; //平方公里
											}
										}
									} else { //直辖市
										areaCount += cityData.area / 1000000; //平方公里
									}
								}
							}
						}
						return areaCount;
					}
					let cityList = provinceData.children; //市列表
					if (cityList != null) {
						for (let j = 0; j < cityList.length; j++) {
							let cityData = cityList[j];
							if (cityData != null) {
								let cityName = cityData.name; //市
								if (type == "2" && city == cityName) {
									let areaList = cityData.children; //区县列表
									if (areaList.length > 0) {
										for (let j = 0; j < areaList.length; j++) {
											let areaData = areaList[j];
											if (areaData != null) {
												areaCount += areaData.area / 1000000; //平方公里
											}
										}
									} else { //直辖市的区县
										areaCount = cityData.area / 1000000; //平方公里
									}
									return areaCount;
								}
								let areaList = cityData.children; //区县列表
								if (areaList != null) {
									for (let j = 0; j < areaList.length; j++) {
										let areaData = areaList[j];
										if (areaData != null) {
											let areaName = areaData.name; //区县
											if (type == "3" && area == areaName) {
												areaCount += areaData.area / 1000000; //平方公里
												return areaCount;
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	return areaCount;
}
//查询抽样点调查列表
const surveyList = ref([]); //抽样点调查列表
const getSurveyList = () => {
	loading.value = true;
	mapAllListSurvey().then(response => {
		surveyList.value = response.data;
		console.log("查询抽样点调查列表");
		// console.log(surveyList.value);
		loading.value = false;
	});
}
//查询行政区划树列表
const districtTreeList = ref([]);
const districtBoundaryList = ref([]); //行政区划经纬度信息
const districtCount = ref(0); //选择的行政区划数量
//查询行政区划经纬度信息
function getDistrictBoundaryByCode(codeList) {
	for (let m = 0; m < codeList.length; m++) {
		let code = codeList[m];
		//查询行政区划经纬度信息
		console.log("查询行政区划经纬度信息" + code);
		getDistrictBoundary(code).then((response) => {
			nextTick(() => {
				console.log("查询行政区划经纬度信息result:");
				console.log(response.data);
				//districtBoundaryList.value.push(response.data.coordinate);
				//截取数据防止报错--仅用于展示不保存
				let subStr = response.data.coordinate;
				subStr = subStr.substring(0, 1000);
				districtBoundaryList.value.push(subStr);
				if (districtCount.value == districtBoundaryList.value.length) { //判断是否全部查询完毕
					let region = "";
					let list = districtBoundaryList.value;
					for (let i = 0; i < list.length; i++) {
						if (i > 0) {
							region += ";";
						}
						region += list[i];
					}
					console.log("全部查询完毕--行政区划经纬度信息");
					queryParamsAdd.value.taskRegion = region;
					//新建任务
					proxy.$refs["rulesForm"].validate((vaild) => {
						if (!vaild) {
							return;
						}
						getTaskNum();
						subTaskData.value = [];
						title.value = "新建任务";
						num.value = 0;
						openAdd.value = true;
						//地图获取行政区划总面积
						let area = getAllSelectArea(queryParamsAdd.value.parentdistrictList);
						queryParamsAdd.value.taskArea = area.toString();
						proxy.$modal.closeLoading();
					});
				}
			});
		});
	}
}
//根据所有省市县全名字符串获取codelist
function getCodeByAllName(allName) {
	let allCodeList = [];
	if (allName != null && allName != "") {
		let array = allName.split("、");
		//获取行政区划树列表
		let treeList = districtTreeList.value;
		for (let i = 0; i < array.length; i++) {
			let name = array[i];
			let code = null;
			let arr = name.split('-');
			if (arr.length == 1) { //省或直辖市
				if (treeList != null && treeList.length > 0) {
					for (let i = 0; i < treeList.length; i++) {
						let provinceData = treeList[i]; //省节点
						if (provinceData != null) {
							let provinceName = provinceData.name; //省
							if (name == provinceName) {
								let provinceCode = provinceData.code; //省编码
								code = provinceCode;
								break;
							}
						}
					}
				}
			} else if (arr.length == 2) { //市或直辖市的区县
				if (treeList != null && treeList.length > 0) {
					for (let i = 0; i < treeList.length; i++) {
						let provinceData = treeList[i]; //省节点
						if (provinceData != null) {
							let provinceName = provinceData.name; //省
							if (arr[0] == provinceName) {
								let bool = false;
								let cityList = provinceData.children; //市列表
								if (cityList != null) {
									for (let j = 0; j < cityList.length; j++) {
										let cityData = cityList[j];
										if (cityData != null) {
											let cityName = cityData.name; //市
											if (arr[1] == cityName) {
												let cityCode = cityData.code; //市编码
												code = cityCode;
												bool = true;
												break;
											}
										}
									}
								}
								if (bool) {
									break;
								}
							}
						}
					}
				}
			} else if (arr.length == 3) { //区县
				if (treeList != null && treeList.length > 0) {
					for (let i = 0; i < treeList.length; i++) {
						let provinceData = treeList[i]; //省节点
						let bool = false;
						if (provinceData != null) {
							let provinceName = provinceData.name; //省
							if (arr[0] == provinceName) {
								let cityList = provinceData.children; //市列表
								if (cityList != null) {
									for (let j = 0; j < cityList.length; j++) {
										let cityData = cityList[j];
										if (cityData != null) {
											let cityName = cityData.name; //市
											if (arr[1] == cityName) {
												let areaList = cityData.children; //区县列表
												if (areaList != null) {
													for (let j = 0; j < areaList.length; j++) {
														let areaData = areaList[j];
														if (areaData != null) {
															let areaName = areaData.name; //区县
															if (arr[2] == areaName) {
																let areaCode = areaData.code; //区县编码
																code = areaCode;
																bool = true;
																break;
															}
														}
													}
												}
												if (bool) {
													break;
												}
											}
										}
									}
								}
							}
						}
						if (bool) {
							break;
						}
					}
				}
			}
			//添加code
			allCodeList.push(code);
		}
	}

	return allCodeList;
}
function getProvinceCodeByAllName(allName) {
	let allCodeList = [];
	if (allName != null && allName != "") {
		let array = allName.split("、");
		//获取行政区划树列表
		let treeList = districtTreeList.value;
		for (let i = 0; i < array.length; i++) {
			let name = array[i].split('-')[0];
			let code = null;
			let arr = name;
			if (treeList != null && treeList.length > 0) {
				for (let i = 0; i < treeList.length; i++) {
					let provinceData = treeList[i];//省节点
					if (provinceData != null) {
						let provinceName = provinceData.name;//省
						if (name == provinceName) {
							let provinceCode = provinceData.code;//省编码
							code = provinceCode;
							break;
						}
					}
				}
			}
			allCodeList.push(code);
		}
	}

	return [...new Set(allCodeList)];
}

//获取新建子任务地图区域信息
function getSubTaskMapRegion(type) {
	//type:okSubAdd保存子任务|okSubAddNext保存并创建下一个子任务
	proxy.$modal.loading("正在保存，请稍候...");
	//地图获取行政区划总面积
	let area = getAllSelectArea([queryParamsSubAdd.value.subdistrictList]);
	queryParamsSubAdd.value.taskArea = area.toString();
	let provinceName = queryParamsSubAdd.value.subdistrictList; //省名
	//根据所有省市县全名字符串获取codelist
	let codeList = getCodeByAllName(provinceName);
	console.log("查询行政区划codeList" + codeList);
	//选择的行政区划数量
	districtCount.value = codeList.length;
	console.log("选择的行政区划数量" + districtCount.value);
	let regionCodes = "";
	for (let i = 0; i < codeList.length; i++) {
		let code = codeList[i];
		if (i > 0) {
			regionCodes += ",";
		}
		regionCodes += code;
	}
	districtBoundaryList.value = []; //清空行政区划经纬度
	if (queryParamsAdd.value.taskRegion.indexOf("MULTIPOLYGON") == -1) { //地图圈选父任务
		console.log("地图圈选父任务");
		queryParamsSubAdd.value.taskRegion = queryParamsAdd.value.taskRegion;
		queryParamsSubAdd.value.regionCodes = ""; //清空
	} else { //行政区划选择父任务
		console.log("行政区划选择父任务");
		let parentRegionCodes = queryParamsAdd.value.regionCodes;
		console.log("父任务行政区划code" + parentRegionCodes + ",子任务选择省份" + regionCodes);
		let tempCode = regionCodes.substring(0, 2); //省份code保留2位
		console.log("tempCode:" + tempCode);
		let parentRegionCodeArray = parentRegionCodes.split(",");
		let childRegionCode = "";
		for (let i = 0; i < parentRegionCodeArray.length; i++) {
			let parentRegionCode = parentRegionCodeArray[i];
			if (parentRegionCode.indexOf(tempCode) == 0) { //省份相同2位
				if (childRegionCode != "") {
					childRegionCode += ",";
				}
				childRegionCode += parentRegionCode;
			}
		}
		console.log("子任务行政区划" + childRegionCode);
		queryParamsSubAdd.value.regionCodes = childRegionCode; //地图行政区划code,code字符串
		console.log("行政区划选择父任务");
	}
	console.log(queryParamsAdd.value);
	//查询子任务行政区划经纬度信息
	for (let m = 0; m < codeList.length; m++) {
		let code = codeList[m];
		//查询行政区划经纬度信息
		console.log("查询子任务行政区划经纬度信息" + code);
		getDistrictBoundary(code).then((response1) => {
			nextTick(() => {
				console.log("查询子任务行政区划经纬度信息result:");
				console.log(response1.data);
				districtBoundaryList.value.push(response1.data.coordinate);
				if (districtCount.value == districtBoundaryList.value.length) { //判断是否全部查询完毕
					let region = "";
					let list = districtBoundaryList.value;
					for (let i = 0; i < list.length; i++) {
						if (i > 0) {
							region += ";";
						}
						region += list[i];
					}
					console.log("全部查询完毕--子任务行政区划经纬度信息");
					if (queryParamsAdd.value.taskRegion.indexOf("MULTIPOLYGON") == -1) { //地图圈选父任务
						console.log("获取子任务区域经纬度（地图圈选父任务与省份的交集）");
						//获取子任务区域经纬度（地图圈选父任务与省份的交集）
						queryParamsSubAdd.value.taskRegion = getSubTaskRegionIntersection(queryParamsAdd.value.taskRegion, region);
					} else { //行政区划选择父任务
						//截取数据防止报错--仅用于展示不保存
						region = region.substring(0, 10000);
						queryParamsSubAdd.value.taskRegion = region;
					}
					console.log(queryParamsSubAdd.value.subdistrictList);
					//queryParamsSubAdd.value.taskDistrict = queryParamsSubAdd.value.subdistrictList;//任务区域-省份
					console.log("子任务地图行政区划code,code字符串：");
					console.log(queryParamsSubAdd.value.regionCodes);
					proxy.$modal.closeLoading();
					if (type == "okSubAdd") { //
						proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
							if (!vaild) {
								return;
							}
							if (queryGroupObj.value) {
								queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
								queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
								queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
								queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
							}
							console.log("输出任务地区：");
							console.log(queryParamsSubAdd.value.subdistrictList);
							// 新增
							if (titleSub.value == "新建子任务") {
								if (numAdd.value == 1) {
									proxy.$modal.loading();
									addSubTask({
										...queryParamsSubAdd.value,
										subdistrictList: [queryParamsSubAdd.value.subdistrictList],
										taskYear: parentTaskYear.value,
										parentTask: parentTaskCode.value,
										parentId: parentTaskId.value,
										parentdistrictList: queryParamsAdd.value.parentdistrictList,
									}).then((response) => {
										proxy.$modal.closeLoading();
										openAddSub.value = false;
										proxy.$modal.msgSuccess(response.data.message);
										resetSubData();
										getList();
										queryGroupObj.value = undefined;
										getSubList(parentTaskId.value);
									}).catch(err => { proxy.$modal.closeLoading(); });
								} else {
									proxy.$modal.loading();
									addTask({
										parentTask: queryParamsAdd.value,
										subTask: {
											...queryParamsSubAdd.value,
											subdistrictList: [queryParamsSubAdd.value.subdistrictList],
											taskYear: parentTaskYear.value,
											parentTask: parentTaskCode.value,
										},
									}).then((response) => {
										proxy.$modal.closeLoading();
										proxy.$modal.msgSuccess("保存成功");
										numAdd.value = 1;
										openAddSub.value = false;
										resetSubData();
										getSubList(response.data.parentTaskId);
										queryGroupObj.value = undefined;
										parentTaskId.value = response.data.parentTaskId;
										//地图传参
										isSaveMapPolygon.value = true;
									}).catch(err => { proxy.$modal.closeLoading(); });
								}
							}
						});
					} else if (type == "okSubAddNext") { //保存并创建下一个子任务
						proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
							if (!vaild) {
								return;
							}
							// 新增
							if (queryGroupObj.value) {
								queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
								queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
								queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
								queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
							}
							if (numAdd.value == 1) {
								proxy.$modal.loading();
								addSubTask({
									...queryParamsSubAdd.value,
									subdistrictList: [queryParamsSubAdd.value.subdistrictList],
									taskYear: parentTaskYear.value,
									parentTask: parentTaskCode.value,
									parentId: parentTaskId.value,
									parentdistrictList: queryParamsAdd.value.parentdistrictList,
								}).then((response) => {
									proxy.$modal.closeLoading();
									proxy.$modal.msgSuccess("保存成功");
									getSubTaskNum(parentTaskCode.value);
									resetSubData();
									getList();
									queryGroupObj.value = undefined;
									getSubList(parentTaskId.value);
								}).catch(err => { proxy.$modal.closeLoading(); });
							} else {
								proxy.$modal.loading();
								addTask({
									parentTask: queryParamsAdd.value,
									subTask: {
										...queryParamsSubAdd.value,
										subdistrictList: [queryParamsSubAdd.value.subdistrictList],
										taskYear: parentTaskYear.value,
										parentTask: parentTaskCode.value,
									},
								}).then((response) => {
									proxy.$modal.closeLoading();
									proxy.$modal.msgSuccess("保存成功");
									numAdd.value = 1;
									getSubTaskNum(parentTaskCode.value);
									resetSubData();
									// rulesFormSubAdd.value.clearValidate();
									getSubList(response.data.parentTaskId);
									queryGroupObj.value = undefined;
									parentTaskId.value = response.data.parentTaskId;
									//地图传参
									isSaveMapPolygon.value = true;
								}).catch(err => { proxy.$modal.closeLoading(); });
							}
						});
					}
				}
			});
		});
	}
}

//地图圈选查询行政区划结果列表
const taskRegionResultNameCodeList = ref([]);
//根据地图圈选区域，查询行政区划--省|市|区县的名称和code列表
function queryTaskRegionNameCodeListByGeomText(geomText) {
	importShpTxtWkt.value = "";//清空
	console.log("查询行政区划名称和code列表");
	queryProvinceCityCountyNameCodeListByGeomText(geomText).then((response) => {
		nextTick(() => {
			console.log("查询行政区划名称和code列表result:");
			console.log(response.data);
			taskRegionResultNameCodeList.value = response.data;
		});
	});
}

// 打开查看行动轨迹
function openTrack(row) {
	router.push({
		path: '/sceneexamine/viewTrack',
		query: {
			id: row.id
		}
	})
}
//地图传参--end
// 打开调研点
function probeOpen(row) {
	openSubTask.value = false; //关闭选择子任务的弹出框
	router.push({
		path: '/sceneexamine/mapSurvey',
		query: {
			id: row.id
		}
	})
}
// 打开选择子任务调研
function selectOpen(row) {
	getSubList(row.id);
	openSubTask.value = true;
}

//  结束按钮操作
function handleEnd(row) {
	//if(endFlag.value){
	initIndex.value = 0;
	taskId.value = row.id;
	proxy.$modal.confirm("结束任务后将不可以再修改现场调查数据，请确定是否继续结束该任务？").then(() => {
		checkIsAdopted(row.id).then((response) => {
			if (response.data == true) {
				finishTask(row)
			} else {
				ElMessageBox.confirm(
					`${response.message}，请确定是否继续结束该任务？`,
					'系统提示',
					{
						confirmButtonText: '结束任务',
						cancelButtonText: '取消',
						type: 'warning',
						dangerouslyUseHTMLString: true,
						cancelButtonClass: 'is-plain',
					}
				).then(() => {
					finishTask(row)
				}).catch(() => { })
			}
		})
	})
}
const finishTask = (row) => {
	checkPutLethalityDifference(row.taskNum).then((response) => {
		if (response.data.length == 0) {
			updateIsAdoptByTaskNum(row.taskNum).then((response) => {
				completeTask(row.id).then((response) => {
					proxy.$modal.msgSuccess(response.data.message);
					getList();
				});
			});
		} else {
			endTaskList.value = response.data;
			openEndTask.value = true;
		}
	});
}
/*更新*/
const isUpdate = ref(false);
function update(rkId, cnId, index) {
	isUpdate.value = true;
	updateIsAdopt(rkId, cnId).then((response) => {
		isUpdate.value = false;
		proxy.$modal.msgSuccess(response.message);
		initIndex.value = index + 1;
		if (initIndex.value == endTaskList.value.length) {
			openEndTask.value = false;
			completeTask(taskId.value).then((response) => {
				isUpdate.value = true;
				proxy.$modal.msgSuccess(response.data.message);
				getList();
			}).catch(err => { isUpdate.value = false; });
		}
	});
}
/*不更新*/
const noUpdate = ref(false);
function unUpdate(index) {
	noUpdate.value = true;
	initIndex.value = index + 1;
	if (initIndex.value == endTaskList.value.length) {
		openEndTask.value = false;
		completeTask(taskId.value).then((response) => {
			noUpdate.value = false;
			proxy.$modal.msgSuccess(response.data.message);
			getList();
		}).catch(err => { noUpdate.value = false; });
	}
}
/*切换标签页*/
function handleClick(tab, event) {
	activeName.value = tab.paneName;
	if (tab.index == 1) {
		openArea.value = false;
		resetArea();
		getList()
	} else {
		//隐藏地图
		completeRefreshSceneexamine.value = false;
		//地图查询全部任务
		getAllList();
	}
}

const handleSelectionChange = (selection) => {
	ids.value = selection.map((item) => item.id);
	single.value = selection.length != 1;
	multiple.value = !selection.length;
	selection.forEach(item => {
		if (item.taskStatus == '2') {
			delFlag.value = false;
		} else {
			delFlag.value = true;
		}
		if (item.taskStatus == '0') {
			endFlag.value = false;
		} else {
			endFlag.value = true;
		}
	})
};

/** 搜索按钮操作 */
function handleQuery() {
	queryParams.value.page = 1;
	getList();
}
/** 重置按钮操作 */
function resetQuery() {
	cityData.value = [];
	areaData.value = [];
	proxy.resetForm("queryRef");
	queryParams.value.taskStatus = "";
	handleQuery();
}

/** 获取省列表 */
function getProvinceData() {
	getProvince().then((response) => {
		provinceData.value = response.data;
	});
}

function chooseProvince(value) {
	queryParams.value.city = null;
	queryParams.value.county = null;
	queryParams.value.province = value.name;
	cityData.value = [];
	areaData.value = [];
	getChildArea(value.id).then(response => {
		cityData.value = response.data;
	});
}

function chooseCity(value) {
	queryParams.value.city = value.name;
	queryParams.value.county = null;
	areaData.value = [];
	getChildArea(value.id).then((response) => {
		areaData.value = response.data;
	});
}

function chooseCounty(value) {
	queryParams.value.county = value.name;
}

// 部门  树形数据
// 处理数据
function disposeata(data) {
	data.forEach((item) => {
		item.label = item.name;
		item.key = item.id;
		item.children && disposeata(item.children);
	});
	return data;
}

function getTreeselect() {
	console.log("查询行政区划列表：");
	getAreaTree().then((response) => {
		nextTick(() => {
			//console.log(response.data);
			optionsSelect.value = disposeata(JSON.parse(response.data));
			console.log("行政区划列表");
			//地图行政区划列表
			districtTreeList.value = optionsSelect.value;
			console.log(districtTreeList.value);
		});
	});
}

function getCheckedArea() {
	let taskDistrict = checkedAreaRef.value.getCheckedNodes();
	taskDistrict = taskDistrict.filter(option => !(option.parent && option.parent.checked))
	queryParamsAdd.value.parentdistrictList = taskDistrict.map((item, index) => {
		return item.pathLabels.join("-");
	});
	var arr = JSON.parse(JSON.stringify(queryParamsAdd.value.parentdistrictList));
	queryParamsAdd.value.parentdistrictList = arr;
	taskDistrictName.value = getDistrict(arr);
	districtListName.value = getProvinces(taskDistrictName.value);
}

/** 获取列表操作 */
function getList() {
	if (activeName.value == "first") {
		//地图查询全部任务
		getAllList();
	} else {
		loading.value = true;
		getTask(queryParams.value).then((response) => {
			listData.value = response.data.rows;
			listData.value.forEach(item => {
				item.flag = item.groupId != "" || item.children.some((val) => {
					if (val.groupId != "") {
						return true
					}
				})
			})
			loading.value = false;
			total.value = response.data.total;
		});
	}
}

//地图查询全部任务
function getAllList() {
	// loading.value = true;
	completeRefreshSceneexamine.value = true; //防止地图刷新后不显示
	//地图查询全部任务
	getAllTaskList().then((response) => {
		nextTick(() => {
			allListData.value = response.data;
			//completeRefreshSceneexamine.value = true;//防止地图刷新后不显示
			// loading.value = false;
		});
	});
}

/** 获取子列表操作 */
function getSubList(parentId) {
	loading1.value = true;
	getSubTask({
		parentTaskId: parentId
	}).then((response) => {
		nextTick(() => {
			subTaskData.value = response.data;
			console.log(response.data);
			if (districtListName.value.filter(item => !subTaskData.value.some(cur => cur.taskDistrict.includes(item.value))).length == 0) {
				openAddSub.value = false;
			}
		});
		loading1.value = false;
	});
}

/** 删除按钮操作 */
function handleDelete() {
	if (delFlag.value) {
		proxy.$modal
			.confirm("是否确认删除该任务关联的所有信息，请确认是否要删除？",)
			.then(function () {
				return delTask(ids.value.join(","));
			})
			.then(() => {
				proxy.$refs['tableRef']?.clearSelection();
				getList();
				proxy.$modal.msgSuccess("删除成功");
			})
			.catch(() => { });
	} else {
		proxy.$modal.msgWarning('结束状态的任务不可删除');
	}
}

// 删除子任务
function delSubTask(row) {
	proxy.$modal
		.confirm("确认删除该任务？")
		.then(function () {
			return delTask(row.id);
		})
		.then(() => {
			proxy.$modal.msgSuccess("删除成功");
			getSubList(row.parentId);
			getList();
		})
		.catch(() => { });
}

// 分配开关
function fenPei(row) {
	num.value = 1;
	queryGroupObj.value = undefined;
	fpId.value.id = row.id;
	fpId.value.parentId = row.parentId;
	fpId.value.taskName = row.taskName;
	fpId.value.createUser = row.createUser;
	openFp.value = true;
}
// 新建分配开关
function fenPeiAdd() {
	queryGroupObj.value = undefined;
	openFp.value = true;
}

// 分配小组
function assignment() {
	groupFp({
		...queryGroupObj.value,
		groupId: queryGroupObj.value.id,
		id: fpId.value.id,
		parentId: fpId.value.parentId,
		taskName: fpId.value.taskName,
	}).then((response) => {
		proxy.$modal.msgSuccess("分配成功");
		openFp.value = false;
		queryGroupObj.value = undefined;
		getList();
		getSubList(fpId.value.parentId);
	});
}
// 分配确认
// function okFp() {
//   if (num.value == 0) {
//     openFp.value = false;
//     queryParamsAdd.value.groupName = queryGroupObj.value.groupName;
//     queryParamsAdd.value.groupLeader = queryGroupObj.value.groupLeader;
//     queryParamsAdd.value.groupId = queryGroupObj.value.id;
//     queryParamsAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
//   } else {
//     assignment();
//   }
// }
function cancelP() {
	openFp.value = false;
	nextTick(() => {
		proxy.$refs["fpRef"].reset();
	})
}

function queryGroup(val) {
	queryGroupObj.value = val;
	if (num.value == 0) {
		openFp.value = false;
		queryParamsAdd.value.groupName = queryGroupObj.value.groupName;
		queryParamsAdd.value.groupLeader = queryGroupObj.value.groupLeader;
		queryParamsAdd.value.groupId = queryGroupObj.value.id;
		queryParamsAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
	} else if (num.value == 2) {
		openFp.value = false;
		queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
		queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
		queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
		queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
	} else {
		assignment();
	}
}
// 打开行政选区
function areaSelect() {
	openArea.value = true;
	// rulesForm.value.clearValidate();
	resetArea();
}
// 选择关闭后的回调
function closeSelect() {
	openArea.value = false;
	resetArea();
}

function resetArea() {
	selectArea.value = [];
	proxy.resetForm("rulesForm");
}
// 新建任务
function add() {
	proxy.$modal.loading("正在查询，请稍候...");
	districtBoundaryList.value = []; //行政区划经纬度信息
	//查询行政区划经纬度信息
	console.log("查询行政区划经纬度信息", taskDistrictName.value);
	//地图获取行政区划总面积
	//let area = getAllSelectArea(queryParamsAdd.value.parentdistrictList);
	//queryParamsAdd.value.taskArea = area.toString();
	//根据所有省市县全名字符串获取codelist
	let codeList = getCodeByAllName(taskDistrictName.value);
	console.log("查询行政区划codeList", codeList);
	//选择的行政区划数量
	districtCount.value = codeList.length;
	console.log("选择的行政区划数量" + districtCount.value);
	let regionCodes = "";
	for (let i = 0; i < codeList.length; i++) {
		let code = codeList[i];
		if (i > 0) {
			regionCodes += ",";
		}
		regionCodes += code;
	}
	resetAdd();
	queryParamsAdd.value.regionCodes = regionCodes; //地图行政区划code,code字符串
	//查询行政区划经纬度信息
	getDistrictBoundaryByCode(codeList);
	queryGroupObj.value = undefined
	/*//新建任务
	proxy.$refs["rulesForm"].validate((vaild) => {
		if (!vaild) {
			return;
		}
		//resetAdd();
		getTaskNum();
		subTaskData.value = [];
		title.value = "新建任务";
		num.value = 0;
		openAdd.value = true;
		//地图获取行政区划总面积
		let area = getAllSelectArea(queryParamsAdd.value.parentdistrictList);
		queryParamsAdd.value.taskArea = area.toString();
		proxy.$modal.closeLoading();
	});*/
}

// 新建子任务
function addSub(row) {
	numAdd.value = 1;
	resetSubData();
	getSubTaskNum(row.taskNum);
	parentTaskCode.value = row.taskNum;
	parentTaskYear.value = row.taskYear;
	parentTaskId.value = row.id;
	districtListName.value = getProvinces(row.taskDistrict);
	queryParamsAdd.value.parentdistrictList = row.taskDistrict.split('、');
	subTaskData.value = row.children;
	console.log("新建子任务row:", row);
	//任务区域
	queryParamsAdd.value.taskRegion = row.taskRegion;
	if (queryParamsAdd.value.taskRegion.indexOf("MULTIPOLYGON") == -1) { //地图绘制区域
		console.log("地图绘制区域");
	} else {
		console.log("行政区划选择区域");
		//根据所有省市县全名字符串获取codelist
		let codeList = getCodeByAllName(row.taskDistrict);
		console.log("查询行政区划codeList");
		console.log(codeList);
		//选择的行政区划数量
		districtCount.value = codeList.length;
		console.log("选择的行政区划数量" + districtCount.value);
		let regionCodes = "";
		for (let i = 0; i < codeList.length; i++) {
			let code = codeList[i];
			if (i > 0) {
				regionCodes += ",";
			}
			regionCodes += code;
		}
		//父任务行政区划code,code字符串
		queryParamsAdd.value.regionCodes = regionCodes; //地图行政区划code,code字符串
	}
	titleSub.value = "新建子任务";
	num.value = 2;
	openAddSub.value = true;
}

// 新建子任务
function addSub2(row) {
	proxy.$refs["rulesFormAdd"].validate((vaild) => {
		if (!vaild) {
			return;
		}
		resetSubData();
		getSubTaskNum(row.taskNum);
		titleSub.value = "新建子任务";
		num.value = 2;
		openAddSub.value = true;
		parentTaskCode.value = row.taskNum;
		parentTaskYear.value = row.taskYear;
	});
}

/** 查看按钮操作 */
function handleDetail(id) {
	detailTask({
		id: id
	}).then((response) => {
		nextTick(() => {
			detilList.preAssessTaskEntity = response.data.preAssessTaskEntity;
			detilList.memberlist = response.data.memberlist;
			detilList.expertlist = response.data.expertlist;
			openDetail.value = true;
		});
	});
}

// 修改父任务
function updateParentHandle(row) {
	title.value = "修改任务";
	num.value = 0;
	detailTask({
		id: row.id
	}).then((response) => {
		queryParamsAdd.value = {
			...response.data.preAssessTaskEntity,
			expertlist: response.data.expertlist,
			memberlist: response.data.memberlist,
			geom: '',
		};
		openAdd.value = true;
	});
}

// 修改子任务
function updateSubHandle(row) {
	num.value = 2;
	openAddSub.value = true;
	titleSub.value = "修改子任务";
	parentTaskId.value = row.parentId;
	detailTask({
		id: row.id
	}).then((response) => {
		nextTick(() => {
			queryParamsSubAdd.value = {
				...response.data.preAssessTaskEntity,
				expertlist: response.data.expertlist,
				memberlist: response.data.memberlist,
				geom: '',
			};
		});
	});
}
// 改变年份
function changeYear(val) {
	getTaskNum(val)
}
// 获取任务编码
function getTaskNum(taskYear) {
	getTaskBian({
		taskYear: taskYear
	}).then((response) => {
		nextTick(() => {
			queryParamsAdd.value.taskNum = response.data;
		});
	});
	return queryParamsAdd.value.taskNum;
}

// 获取子任务编码
function getSubTaskNum(taskNum) {
	getSubTaskBian({
		taskNum: taskNum
	}).then((response) => {
		nextTick(() => {
			queryParamsSubAdd.value.taskNum = response.data;
		});
	});
	return queryParamsAdd.value.taskNum;
}

/** 提交按钮 */
function okAdd() {
	console.log("提交按钮：");
	proxy.$refs["rulesFormAdd"].validate((vaild) => {
		if (!vaild) {
			return;
		}
		if (queryGroupObj.value) {
			queryParamsAdd.value.groupName = queryGroupObj.value.groupName;
			queryParamsAdd.value.groupLeader = queryGroupObj.value.groupLeader;
			queryParamsAdd.value.groupId = queryGroupObj.value.id;
			queryParamsAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
		}

		// 新增
		if (title.value == "新建任务") {
			console.log("新建任务保存：");
			proxy.$modal.loading("正在保存...");
			addTask({
				parentTask: queryParamsAdd.value
			}).then((response) => {
				proxy.$modal.closeLoading();
				openAdd.value = false;
				proxy.$modal.msgSuccess("保存成功");
				if(queryParamsAdd.value.groupName == ''&& getProvinceCodeByAllName(taskDistrictName.value.replace(/,/g, '、')).length > 1 && subTaskData.value.length != getProvinceCodeByAllName(taskDistrictName.value.replace(/,/g, '、')).length){
					ElMessageBox.alert('新建任务为跨省任务，请在新建任务完成后新建子任务，如不需要可忽略此提示。', '消息通知', {
  					  confirmButtonText: '确定',
  					})
				}
				resetAdd();
				getList();
				openArea.value = false;
				form.value.taskDistrict = '';
				//地图传参
				isSaveMapPolygon.value = true;
			}).catch(() => {
        proxy.$modal.closeLoading();
      });
		} else {
			//截取数据防止报错--仅用于展示不保存
			let subStr = queryParamsAdd.value.taskRegion;
			subStr = subStr.substring(0, 10000);
			queryParamsAdd.value.taskRegion = subStr;
			// 修改
			proxy.$modal.loading("正在修改...");
			updateTask(queryParamsAdd.value).then((response) => {
				proxy.$modal.closeLoading();
				openAdd.value = false;
				proxy.$modal.msgSuccess("修改成功");
				resetAdd();
				getList();
			}).catch(() => {
        proxy.$modal.closeLoading();
			});
		}
	});
}

function resetAdd() {
	queryParamsAdd.value.taskYear = '';
	queryParamsAdd.value.taskNum = '';
	queryParamsAdd.value.taskName = '';
	queryParamsAdd.value.taskArea = '';
	queryParamsAdd.value.taskRegion = '';
	queryParamsAdd.value.groupName = '';
	queryParamsAdd.value.groupLeader = '';
	queryParamsAdd.value.groupId = '';
	queryParamsAdd.value.groupLeaderId = '';
	queryParamsAdd.value.memberName = '';
	queryParamsAdd.value.expertName = '';
	queryParamsAdd.value.taskDistrict = ''
	numAdd.value = 2;
	proxy.resetForm("rulesFormAdd");
}
// 取消
function cancelAdd() {
	openAdd.value = false;
	resetAdd()
}

function closeAdd() {
	openAdd.value = false;
	resetAdd();
	openArea.value = false;
	resetArea();
}
/** 提交按钮 */
function okSubAdd() {
	// 新增
	if (titleSub.value == "新建子任务") {
		//获取新建子任务地图区域信息
		getSubTaskMapRegion("okSubAdd");
	} else {
		proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
			if (!vaild) {
				return;
			}
			if (queryGroupObj.value) {
				queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
				queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
				queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
				queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
			}
			//截取数据防止报错--仅用于展示不保存
			let subStr = queryParamsSubAdd.value.taskRegion;
			subStr = subStr.substring(0, 10000);
			queryParamsSubAdd.value.taskRegion = subStr;
			// 修改
			updateTask(queryParamsSubAdd.value).then((response) => {
				openAddSub.value = false;
				proxy.$modal.msgSuccess("修改成功");
				getSubList(parentTaskId.value);
				getList();
				resetSubData();
			});
		});
	}
	/* proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
		 if (!vaild) {
			 return;
		 }
		 if (queryGroupObj.value) {
			 queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
			 queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
			 queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
			 queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
		 }
		 // 新增
		 if (titleSub.value == "新建子任务") {
			 if (numAdd.value == 1) {
				 addSubTask({
					 ...queryParamsSubAdd.value,
					 subdistrictList: [queryParamsSubAdd.value.subdistrictList],
					 taskYear: parentTaskYear.value,
					 parentTask: parentTaskCode.value,
					 parentId: parentTaskId.value,
					 parentdistrictList:queryParamsAdd.value.parentdistrictList,
				 }).then((response) => {
					 openAddSub.value = false;
					 proxy.$modal.msgSuccess(response.data.message);
					 resetSubData();
					 getList();
					 queryGroupObj.value = undefined;
					 getSubList(parentTaskId.value);
				 });
			 } else {
				 addTask({
					 parentTask: queryParamsAdd.value,
					 subTask: {
						 ...queryParamsSubAdd.value,
						 subdistrictList: [queryParamsSubAdd.value.subdistrictList],
						 taskYear: parentTaskYear.value,
						 parentTask: parentTaskCode.value,
					 },
				 }).then((response) => {
					 proxy.$modal.msgSuccess("保存成功");
					 numAdd.value = 1;
					 openAddSub.value = false;
					 resetSubData();
					 getSubList(response.data.parentTaskId);
					 queryGroupObj.value = undefined;
					 parentTaskId.value = response.data.parentTaskId;
					 //地图传参
					 isSaveMapPolygon.value = true;
				 });
			 }
		 } else {
			 // 修改
			 updateTask(queryParamsSubAdd.value).then((response) => {
				 openAddSub.value = false;
				 proxy.$modal.msgSuccess("修改成功");
				 getSubList(parentTaskId.value);
				 getList();
				 resetSubData();
			 });
		 }
	 });*/
}

function okSubAddNext() {
	//获取新建子任务地图区域信息
	getSubTaskMapRegion("okSubAddNext");
	/*proxy.$refs["rulesFormSubAdd"].validate((vaild) => {
		if (!vaild) {
			return;
		}
		// 新增
		if (queryGroupObj.value) {
			queryParamsSubAdd.value.groupName = queryGroupObj.value.groupName;
			queryParamsSubAdd.value.groupLeader = queryGroupObj.value.groupLeader;
			queryParamsSubAdd.value.groupId = queryGroupObj.value.id;
			queryParamsSubAdd.value.groupLeaderId = queryGroupObj.value.groupLeaderId;
		}
		if (numAdd.value == 1) {
			addSubTask({
				...queryParamsSubAdd.value,
				subdistrictList: [queryParamsSubAdd.value.subdistrictList],
				taskYear: parentTaskYear.value,
				parentTask: parentTaskCode.value,
				parentId: parentTaskId.value,
				parentdistrictList:queryParamsAdd.value.parentdistrictList,
			}).then((response) => {
				proxy.$modal.msgSuccess("保存成功");
				getSubTaskNum(parentTaskCode.value);
				resetSubData();
				getList();
				queryGroupObj.value = undefined;
				getSubList(parentTaskId.value);
			});
		} else {
			addTask({
				parentTask: queryParamsAdd.value,
				subTask: {
					...queryParamsSubAdd.value,
					subdistrictList: [queryParamsSubAdd.value.subdistrictList],
					taskYear: parentTaskYear.value,
					parentTask: parentTaskCode.value,
				},
			}).then((response) => {
				proxy.$modal.msgSuccess("保存成功");
				numAdd.value = 1;
				getSubTaskNum(parentTaskCode.value);
				resetSubData();
				// rulesFormSubAdd.value.clearValidate();
				getSubList(response.data.parentTaskId);
				queryGroupObj.value = undefined;
				parentTaskId.value = response.data.parentTaskId;
				//地图传参
				isSaveMapPolygon.value = true;
			});
		}
	});*/
}

function resetSubData() {
	queryParamsSubAdd.value.taskYear = '';
	queryParamsSubAdd.value.taskNum = '';
	queryParamsSubAdd.value.taskName = '';
	queryParamsSubAdd.value.taskArea = '';
	queryParamsSubAdd.value.taskRegion = '';
	queryParamsSubAdd.value.subdistrictList = '';
	queryParamsSubAdd.value.taskDistrict = '',
		queryParamsSubAdd.value.groupName = '';
	queryParamsSubAdd.value.groupLeader = '';
	queryParamsSubAdd.value.groupLeaderId = '';
	queryParamsSubAdd.value.groupId = '';
	proxy.resetForm("rulesFormSubAdd");
	// subTaskData.value = [];
}
// 取消新建子任务
function cancelAddSub() {
	openAddSub.value = false;
	getSubList(parentTaskId.value)
}

getYear();
getList();
getProvinceData();
getTreeselect();
</script>
<style scoped lang="scss">
.addTask,
.addSubTask {
	width: 700px;
	margin: 0 auto;

	td {
		width: 350px;
	}

	.label {
		text-align: right;
		display: inline-block;
		color: #606266;
		font-weight: 700;
		height: 32px;
		width: 142px;
		padding-right: 14px;
	}
}

h3 {
	color: #333;
	height: 21px;
	font-size: 16px;
	line-height: 21px;
	display: flex;
	align-items: center;
	margin-left: 40px;

	span {
		margin-right: 12px;
		display: inline-block;
		width: 3px;
		height: 16px;
		background: #333;
	}
}

.areaDialog {
	text-align: center;
	.close {
		text-align: right;

		.el-icon {
			color: #606266;
			padding: 20px 0;
			margin-right: 10px;
			right: 0px;
			font-size: 22px;
		}
	}

	width: 320px;
	position: absolute;
	top: 270px;
	left: 320px;
	background: rgba($color: #fff, $alpha: 0.9);
}

.mainTitle {
	font-size: 16px;
	font-weight: bold;
}

.subTitle {
	font-size: 16px;
	font-weight: bold;
}

.tableDialog {
	width: 100%;
	border-collapse: collapse;
	border: 1px solid #e5ebf7;
	margin-bottom: 20px;

	.tableHead {
		background: #f5f9fe;

		td {
			padding: 10px 0px;
		}
	}

	tr {
		height: 40px;
	}

	td {
		border: 1px solid #e5ebf7;
		text-align: center;

		:deep(.el-form-item__content) {
			flex-wrap: nowrap !important;

			.el-input-number {
				width: 75px !important;
			}
		}
	}

	.el-button--default {
		border: none !important;
	}
}
.new-uploadDiv {
	position: absolute;
	top: 16px;
	left: 100px;
	width: 358px;
	height: 260px;
	background-color: #fff;
	box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.2);
	border: 1px solid #707070;
	border-radius: 4px;
}

.new-uploadDiv-inner {
	position: absolute;
	top: 20px;
	left: 30px;
	right: 30px;
	bottom: 0px;
}

.new-fileBtn {
	position: absolute;
	top: 50px;
	left: 0px;
	width: 70px;
}

.new-fieldInfoBtn {
	position: absolute;
	top: 70px;
	left: 15px;
	width: 70px;
	color: var(--el-color-primary);
}

.new-filesTextArea {
	position: absolute;
	left: 80px;
	top: 50px;
	right: 0px;
	height: 100px;
}

.new-uploadBtnDiv {
	position: absolute;
	left: 80px;
	right: 0px;
	bottom: 20px;
}

.new-closeBtnDiv {
	position: absolute;
	right: 0px;
	bottom: 20px;
}
:deep(.el-cascader) {
  .el-input{
    min-height: 32px;
  }
}
</style>